package com.vrv.app.cyberspace.modules.sys.Interceptor;

import com.alibaba.fastjson.JSON;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

import static com.vrv.app.cyberspace.common.utils.JSONResult.renderError;

/**
 * @Description 
 * @Author by sm
 * @Create 2018-01-08 17:17
 */

public class UserInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
        if (request.getSession().getAttribute("user")!=null){
            return true;
        }
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter p = response.getWriter();
        p.print(JSON.toJSONString(renderError("授权认证失败，请先调用getUser()接口！")));
        return false;
    }
}
